<template>
  <el-card class="box-card">
  <template #header>
    登录
  </template>
  <el-form :model="form" label-width="120px">
    <el-form-item label="Account name">
      <el-input v-model="form.account" />
    </el-form-item>
    <el-form-item label="Password">
      <el-input v-model="form.password" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">Login</el-button>
      <el-button>Cancel</el-button>
    </el-form-item>
  </el-form>
  </el-card>
</template>

<script lang="ts" setup>
import {onActivated, onDeactivated, onMounted, onUnmounted, onUpdated, reactive} from 'vue'

import { ElNotification } from 'element-plus'

import { login } from '/src/views/login.ts'


// do not use same name with ref
const form = reactive({
  account: '',
  password: ''
})

onMounted(()=>{
  console.log("mounted");
})

onActivated(()=>{
  console.log("activated");
})

onUpdated(()=>{
  console.log("updated")
})

onDeactivated(()=>{
  console.log("deactivated");
})

onUnmounted(()=>{
  console.log("onUnmounted");
})

const onSubmit = () => {
  localStorage.setItem("user",String(true));
   login(form.account,form.password).then(response => {
     console.log(response);
     const {data}=response;
     ElNotification({
       title: '欢迎你',
       message: JSON.stringify(data.data),
       type: 'success',
       position: 'bottom-right'
     })
   })
}
</script>

